package com.abvnet.project.water.project.controller;

import com.abvnet.framework.aspectj.lang.annotation.Log;
import com.abvnet.framework.aspectj.lang.enums.BusinessType;
import com.abvnet.framework.web.controller.BaseController;
import com.abvnet.framework.web.domain.AjaxResult;
import com.abvnet.framework.web.page.TableDataInfo;
import com.abvnet.project.water.project.domain.ProjectProgress;
import com.abvnet.project.water.project.service.IProjectProgressService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目进度信息操作处理
 * 
 * @author duj
 * @date 2019-07-23
 */
@Controller
@RequestMapping("/project/projectProgress")
public class ProjectProgressController extends BaseController {
    private String prefix = "project/projectProgress";
	
	@Autowired
	private IProjectProgressService projectProgressService;

    @RequiresPermissions("project:projectProgress:list")
	@GetMapping()
	public String projectProgress()
	{
	    return prefix + "/list";
	}
	
	/**
	 * 查询项目进度列表
	 */
	@RequiresPermissions("project:projectProgress:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ProjectProgress projectProgress) {
		startPage();
        List<ProjectProgress> list = projectProgressService.selectProjectProgressList(projectProgress);
		return getDataTable(list);
	}
	
	/**
	 * 新增项目进度
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存项目进度
	 */
	@RequiresPermissions("project:projectProgress:add")
	@Log(title = "项目进度", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ProjectProgress projectProgress) {
		return toAjax(projectProgressService.insertProjectProgress(projectProgress));
	}

	/**
	 * 修改项目进度
	 */
	@GetMapping("/edit/{progressId}")
	public String edit(@PathVariable("progressId") Long progressId, ModelMap mmap) {
		ProjectProgress projectProgress = projectProgressService.selectProjectProgressById(progressId);
		mmap.put("projectProgress", projectProgress);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存项目进度
	 */
	@Log(title = "项目进度", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ProjectProgress projectProgress) {
        projectProgressService.batchUpdateProjectProgress(projectProgress.getPpList());
		return success();
	}
	
	/**
	 * 删除项目进度
	 */
	@RequiresPermissions("project:projectProgress:remove")
	@Log(title = "项目进度", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(projectProgressService.deleteProjectProgressByIds(ids));
	}
	
}
